//
//  DrugDetailTableViewCell.m
//  MedicineBox
//
//  Created by dllo on 15/8/26.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "DrugDetailTableViewCell.h"
#import "HomeModel.h"
#import "DKNightVersion.h"
@interface DrugDetailTableViewCell ()

@property (nonatomic, retain) UILabel *nameLabel;
@property (nonatomic, retain) UILabel *namecn;
@property (nonatomic, retain) UILabel *compositionLabel;
@property (nonatomic, retain) UILabel *composition;
@property (nonatomic, retain) UILabel *drugattributeLabel;
@property (nonatomic, retain) UILabel *drugattribute;
@property (nonatomic, retain) UILabel *gongnengLabel;
@property (nonatomic, retain) UILabel *gongneng;
@property (nonatomic, retain) UILabel *usageLabel;
@property (nonatomic, retain) UILabel *usage;
@property (nonatomic, retain) UILabel *adrLabel;
@property (nonatomic, retain) UILabel *adr;
@property (nonatomic, retain) UILabel *contraindicationLabel;
@property (nonatomic, retain) UILabel *contraindication;
@property (nonatomic, retain) UILabel *noteLabel;
@property (nonatomic, retain) UILabel *note;
@property (nonatomic, retain) UILabel *interactionLabel;
@property (nonatomic, retain) UILabel *interaction;
@property (nonatomic, retain) UILabel *storageLabel;
@property (nonatomic, retain) UILabel *storage;
@property (nonatomic, retain) UILabel *shelflifeLabel;
@property (nonatomic, retain) UILabel *shelflife;
@property (nonatomic, retain) UILabel *codenameLabel;
@property (nonatomic, retain) UILabel *codename;
@property (nonatomic, retain) UILabel *standardLabel;
@property (nonatomic, retain) UILabel *standard;
@property (nonatomic, retain) UILabel *specificationdateLabel;
@property (nonatomic, retain) UILabel *specificationdate;
@property (nonatomic, retain) UILabel *refdrugcompanynameLabel;
@property (nonatomic, retain) UILabel *refdrugcompanyname;

@end


@implementation DrugDetailTableViewCell

-(void)dealloc
{
    [_nameStr release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [DKNightVersionManager addClassToSet:self.class];
        self.nightBackgroundColor = UIColorFromRGB(0x343434);
        
        self.nameLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.nameLabel];
        [_nameLabel release];
        
        self.namecn = [[UILabel alloc] init];
        [self.contentView addSubview:self.namecn];
        [_namecn release];
        
        self.compositionLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.compositionLabel];
        [_compositionLabel release];
        
        self.composition = [[UILabel alloc] init];
        [self.contentView addSubview:self.composition];
        [_composition release];
        
        self.drugattributeLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.drugattributeLabel];
        [_drugattributeLabel release];
        
        self.drugattribute = [[UILabel alloc] init];
        [self.contentView addSubview:self.drugattribute];
        [_drugattribute release];
        
        self.gongnengLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.gongnengLabel];
        [_gongnengLabel release];
        
        self.gongneng = [[UILabel alloc] init];
        [self.contentView addSubview:self.gongneng];
        [_gongneng release];
        
        self.usageLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.usageLabel];
        [_usageLabel release];
        
        self.usage = [[UILabel alloc] init];
        [self.contentView addSubview:self.usage];
        [_usage release];
        
        self.adrLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.adrLabel];
        [_adrLabel release];
        
        self.adr = [[UILabel alloc] init];
        [self.contentView addSubview:self.adr];
        [_adr release];
        
        self.contraindicationLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.contraindicationLabel];
        [_contraindicationLabel release];
        
        self.contraindication = [[UILabel alloc] init];
        [self.contentView addSubview:self.contraindication];
        [_contraindication release];
        
        self.noteLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.noteLabel];
        [_noteLabel release];
        
        self.note = [[UILabel alloc] init];
        [self.contentView addSubview:self.note];
        [_note release];
        
        self.usageLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.usageLabel];
        [_usageLabel release];
        
        self.usage = [[UILabel alloc] init];
        [self.contentView addSubview:self.usage];
        [_usage release];
        
        self.interactionLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.interactionLabel];
        [_interactionLabel release];
        
        self.interaction = [[UILabel alloc] init];
        [self.contentView addSubview:self.interaction];
        [_interaction release];
        
        self.storageLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.storageLabel];
        [_storageLabel release];
        
        self.storage = [[UILabel alloc] init];
        [self.contentView addSubview:self.storage];
        [_storage release];
        
        self.shelflifeLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.shelflifeLabel];
        [_shelflifeLabel release];
        
        self.shelflife = [[UILabel alloc] init];
        [self.contentView addSubview:self.shelflife];
        [_shelflife release];
        
        self.codenameLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.codenameLabel];
        [_codenameLabel release];
        
        self.codename = [[UILabel alloc] init];
        [self.contentView addSubview:self.codename];
        [_codename release];
        
        self.standardLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.standardLabel];
        [_standardLabel release];
        
        self.standard = [[UILabel alloc] init];
        [self.contentView addSubview:self.standard];
        [_standard release];
        
        self.specificationdateLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.specificationdateLabel];
        [_specificationdateLabel release];
        
        self.specificationdate = [[UILabel alloc] init];
        [self.contentView addSubview:self.specificationdate];
        [_specificationdate release];
        
        self.refdrugcompanynameLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.refdrugcompanynameLabel];
        [_refdrugcompanynameLabel release];
        
        self.refdrugcompanyname = [[UILabel alloc] init];
        [self.contentView addSubview:self.refdrugcompanyname];
        [_refdrugcompanyname release];



        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat width = self.contentView.frame.size.width - 60;
    self.nameLabel.frame = CGRectMake(20, 20, 100, 10);
    self.nameLabel.textColor = [UIColor blackColor];
    self.nameLabel.font = [UIFont systemFontOfSize:15];
    self.nameLabel.textAlignment = NSTextAlignmentLeft;
    self.nameLabel.text = @"[药品名称]";
    
    self.namecn.frame = CGRectMake(30, 40, width, 10);
    self.namecn.textColor = [UIColor grayColor];
    self.namecn.font = [UIFont systemFontOfSize:13];
    self.namecn.text = [NSString stringWithFormat:@"通用名称:%@", self.nameStr];
}

- (void)valueWithModel:(HomeModel *)model indexPath:(NSIndexPath *)path
{
    
    CGFloat width = self.contentView.frame.size.width - 60;
    
    self.compositionLabel.frame = CGRectMake(20, 60, 100, 10);
    self.compositionLabel.textColor = [UIColor blackColor];
    self.compositionLabel.font = [UIFont systemFontOfSize:15];
    self.compositionLabel.textAlignment = NSTextAlignmentLeft;
    self.compositionLabel.text = @"[成份]";
    
    self.composition.frame = CGRectMake(30, 80, width, [DrugDetailTableViewCell heightWithText:model.composition]);
    self.composition.textColor = [UIColor grayColor];
    self.composition.font = [UIFont systemFontOfSize:15];
    self.composition.textAlignment = NSTextAlignmentLeft;
    self.composition.text = model.composition;
    self.composition.numberOfLines = 0;
    
    self.drugattributeLabel.frame = CGRectMake(20, self.composition.frame.origin.y + self.composition.frame.size.height + 10, 100, 10);
    self.drugattributeLabel.textColor = [UIColor blackColor];
    self.drugattributeLabel.font = [UIFont systemFontOfSize:15];
    self.drugattributeLabel.textAlignment = NSTextAlignmentLeft;
    self.drugattributeLabel.text = @"[性状]";
    
    self.drugattribute.frame = CGRectMake(30, self.drugattributeLabel.frame.size.height + self.drugattributeLabel.frame.origin.y + 10, width, [DrugDetailTableViewCell heightWithText:model.drugattribute]);
    self.drugattribute.textColor = [UIColor grayColor];
    self.drugattribute.font = [UIFont systemFontOfSize:15];
    self.drugattribute.textAlignment = NSTextAlignmentLeft;
    self.drugattribute.text = model.drugattribute;
    self.drugattribute.numberOfLines = 0;
    
    self.gongnengLabel.frame = CGRectMake(20, self.drugattribute.frame.origin.y + self.drugattribute.frame.size.height + 10, 100, 10);
    self.gongnengLabel.textColor = [UIColor blackColor];
    self.gongnengLabel.font = [UIFont systemFontOfSize:15];
    self.gongnengLabel.textAlignment = NSTextAlignmentLeft;
    self.gongnengLabel.text = @"[适应症]";
    
    self.gongneng.frame = CGRectMake(30, self.gongnengLabel.frame.size.height + self.gongnengLabel.frame.origin.y + 10, width, [DrugDetailTableViewCell heightWithText:model.gongneng]);
    self.gongneng.textColor = [UIColor grayColor];
    self.gongneng.font = [UIFont systemFontOfSize:15];
    self.gongneng.textAlignment = NSTextAlignmentLeft;
    self.gongneng.text = model.gongneng;
    self.gongneng.numberOfLines = 0;
    
    self.usageLabel.frame = CGRectMake(20, self.gongneng.frame.origin.y + self.gongneng.frame.size.height + 10, 100, 10);
    self.usageLabel.textColor = [UIColor blackColor];
    self.usageLabel.font = [UIFont systemFontOfSize:15];
    self.usageLabel.textAlignment = NSTextAlignmentLeft;
    self.usageLabel.text = @"[用量用法]";
    
    self.usage.frame = CGRectMake(30, self.usageLabel.frame.size.height + self.usageLabel.frame.origin.y + 10, width, [DrugDetailTableViewCell heightWithText:model.usage]);
    self.usage.textColor = [UIColor grayColor];
    self.usage.font = [UIFont systemFontOfSize:15];
    self.usage.textAlignment = NSTextAlignmentLeft;
    self.usage.text = model.usage;
    self.usage.numberOfLines = 0;
    
    
    self.adrLabel.frame = CGRectMake(20, self.usage.frame.origin.y + self.usage.frame.size.height + 10, 100, 10);
    self.adrLabel.textColor = [UIColor blackColor];
    self.adrLabel.font = [UIFont systemFontOfSize:15];
    self.adrLabel.textAlignment = NSTextAlignmentLeft;
    self.adrLabel.text = @"[不良反应]";
    
    self.adr.frame = CGRectMake(30, self.adrLabel.frame.size.height + self.adrLabel.frame.origin.y + 10, width, [DrugDetailTableViewCell heightWithText:model.adr]);
    self.adr.textColor = [UIColor grayColor];
    self.adr.font = [UIFont systemFontOfSize:15];
    self.adr.textAlignment = NSTextAlignmentLeft;
    self.adr.text = model.adr;
    self.adr.numberOfLines = 0;
    
    self.contraindicationLabel.frame = CGRectMake(20, self.adr.frame.origin.y + self.adr.frame.size.height + 10, 100, 10);
    self.contraindicationLabel.textColor = [UIColor blackColor];
    self.contraindicationLabel.font = [UIFont systemFontOfSize:15];
    self.contraindicationLabel.textAlignment = NSTextAlignmentLeft;
    self.contraindicationLabel.text = @"[禁忌]";
    
    self.contraindication.frame = CGRectMake(30, self.contraindicationLabel.frame.size.height + self.contraindicationLabel.frame.origin.y + 10, width, [DrugDetailTableViewCell heightWithText:model.contraindication]);
    self.contraindication.textColor = [UIColor grayColor];
    self.contraindication.font = [UIFont systemFontOfSize:15];
    self.contraindication.textAlignment = NSTextAlignmentLeft;
    self.contraindication.text = model.contraindication;
    self.contraindication.numberOfLines = 0;
    
    self.noteLabel.frame = CGRectMake(20, self.contraindication.frame.origin.y + self.contraindication.frame.size.height + 10, 100, 10);
    self.noteLabel.textColor = [UIColor blackColor];
    self.noteLabel.font = [UIFont systemFontOfSize:15];
    self.noteLabel.textAlignment = NSTextAlignmentLeft;
    self.noteLabel.text = @"[注意事项]";
    
    self.note.frame = CGRectMake(30, self.noteLabel.frame.size.height + self.noteLabel.frame.origin.y + 10, width, [DrugDetailTableViewCell heightWithText:model.note]);
    self.note.textColor = [UIColor grayColor];
    self.note.font = [UIFont systemFontOfSize:15];
    self.note.textAlignment = NSTextAlignmentLeft;
    self.note.text = model.note;
    self.note.numberOfLines = 0;
    
    self.interactionLabel.frame = CGRectMake(20, self.note.frame.origin.y + self.note.frame.size.height + 10, 100, 10);
    self.interactionLabel.textColor = [UIColor blackColor];
    self.interactionLabel.font = [UIFont systemFontOfSize:15];
    self.interactionLabel.textAlignment = NSTextAlignmentLeft;
    self.interactionLabel.text = @"[药物相互作用]";
    
    self.interaction.frame = CGRectMake(30, self.interactionLabel.frame.size.height + self.interactionLabel.frame.origin.y + 10, width, [DrugDetailTableViewCell heightWithText:model.interaction]);
    self.interaction.textColor = [UIColor grayColor];
    self.interaction.font = [UIFont systemFontOfSize:15];
    self.interaction.textAlignment = NSTextAlignmentLeft;
    self.interaction.text = model.interaction;
    self.interaction.numberOfLines = 0;
    
    self.storageLabel.frame = CGRectMake(20, self.interaction.frame.origin.y + self.interaction.frame.size.height + 10, 100, 10);
    self.storageLabel.textColor = [UIColor blackColor];
    self.storageLabel.font = [UIFont systemFontOfSize:15];
    self.storageLabel.textAlignment = NSTextAlignmentLeft;
    self.storageLabel.text = @"[贮藏]";
    
    self.storage.frame = CGRectMake(30, self.storageLabel.frame.size.height + self.storageLabel.frame.origin.y + 10, width, [DrugDetailTableViewCell heightWithText:model.storage]);
    self.storage.textColor = [UIColor grayColor];
    self.storage.font = [UIFont systemFontOfSize:15];
    self.storage.textAlignment = NSTextAlignmentLeft;
    self.storage.text = model.storage;
    self.storage.numberOfLines = 0;
    
    self.shelflifeLabel.frame = CGRectMake(20, self.storage.frame.origin.y + self.storage.frame.size.height + 10, 100, 10);
    self.shelflifeLabel.textColor = [UIColor blackColor];
    self.shelflifeLabel.font = [UIFont systemFontOfSize:15];
    self.shelflifeLabel.textAlignment = NSTextAlignmentLeft;
    self.shelflifeLabel.text = @"[有效期]";
    
    self.shelflife.frame = CGRectMake(30, self.shelflifeLabel.frame.size.height + self.shelflifeLabel.frame.origin.y + 10, width, [DrugDetailTableViewCell heightWithText:model.shelflife]);
    self.shelflife.textColor = [UIColor grayColor];
    self.shelflife.font = [UIFont systemFontOfSize:15];
    self.shelflife.textAlignment = NSTextAlignmentLeft;
    self.shelflife.text = model.shelflife;
    self.shelflife.numberOfLines = 0;
    
    self.codenameLabel.frame = CGRectMake(20, self.shelflife.frame.origin.y + self.shelflife.frame.size.height + 10, 100, 10);
    self.codenameLabel.textColor = [UIColor blackColor];
    self.codenameLabel.font = [UIFont systemFontOfSize:15];
    self.codenameLabel.textAlignment = NSTextAlignmentLeft;
    self.codenameLabel.text = @"[批准文号]";
    
    self.codename.frame = CGRectMake(30, self.codenameLabel.frame.size.height + self.codenameLabel.frame.origin.y + 10, width, [DrugDetailTableViewCell heightWithText:model.codename]);
    self.codename.textColor = [UIColor grayColor];
    self.codename.font = [UIFont systemFontOfSize:15];
    self.codename.textAlignment = NSTextAlignmentLeft;
    self.codename.text = model.codename;
    self.codename.numberOfLines = 0;
    
    self.standardLabel.frame = CGRectMake(20, self.codename.frame.origin.y + self.codename.frame.size.height + 10, 100, 10);
    self.standardLabel.textColor = [UIColor blackColor];
    self.standardLabel.font = [UIFont systemFontOfSize:15];
    self.standardLabel.textAlignment = NSTextAlignmentLeft;
    self.standardLabel.text = @"[执行标准]";
    
    self.standard.frame = CGRectMake(30, self.standardLabel.frame.size.height + self.standardLabel.frame.origin.y + 10, width, [DrugDetailTableViewCell heightWithText:model.standard]);
    self.standard.textColor = [UIColor grayColor];
    self.standard.font = [UIFont systemFontOfSize:15];
    self.standard.textAlignment = NSTextAlignmentLeft;
    self.standard.text = model.standard;
    self.standard.numberOfLines = 0;
    
    self.specificationdateLabel.frame = CGRectMake(20, self.standard.frame.origin.y + self.standard.frame.size.height + 10, 120, 10);
    self.specificationdateLabel.textColor = [UIColor blackColor];
    self.specificationdateLabel.font = [UIFont systemFontOfSize:15];
    self.specificationdateLabel.textAlignment = NSTextAlignmentLeft;
    self.specificationdateLabel.text = @"[说明书修订日期]";
    
    self.specificationdate.frame = CGRectMake(30, self.specificationdateLabel.frame.size.height + self.specificationdateLabel.frame.origin.y + 10, width, [DrugDetailTableViewCell heightWithText:model.specificationdate]);
    self.specificationdate.textColor = [UIColor grayColor];
    self.specificationdate.font = [UIFont systemFontOfSize:15];
    self.specificationdate.textAlignment = NSTextAlignmentLeft;
    self.specificationdate.text = model.specificationdate;
    self.specificationdate.numberOfLines = 0;
    
    
    self.refdrugcompanynameLabel.frame = CGRectMake(20, self.specificationdate.frame.origin.y + self.specificationdate.frame.size.height + 10, 100, 10);
    self.refdrugcompanynameLabel.textColor = [UIColor blackColor];
    self.refdrugcompanynameLabel.font = [UIFont systemFontOfSize:15];
    self.refdrugcompanynameLabel.textAlignment = NSTextAlignmentLeft;
    self.refdrugcompanynameLabel.text = @"[生产企业]";
    
    self.refdrugcompanyname.frame = CGRectMake(30, self.refdrugcompanynameLabel.frame.size.height + self.refdrugcompanynameLabel.frame.origin.y + 10, width, [DrugDetailTableViewCell heightWithText:model.refdrugcompanyname]);
    self.refdrugcompanyname.textColor = [UIColor grayColor];
    self.refdrugcompanyname.font = [UIFont systemFontOfSize:15];
    self.refdrugcompanyname.textAlignment = NSTextAlignmentLeft;
    self.refdrugcompanyname.text = model.refdrugcompanyname;
    self.refdrugcompanyname.numberOfLines = 0;
    
    
    [ self.drugDetailDelegate bringHeightToController:self.nameLabel.frame.size.height + self.namecn.frame.size.height + self.compositionLabel.frame.size.height + self.composition.frame.size.height + self.drugattributeLabel.frame.size.height + self.drugattribute.frame.size.height + self.gongnengLabel.frame.size.height + self.gongneng.frame.size.height + self.usageLabel.frame.size.height + self.usage.frame.size.height + self.adrLabel.frame.size.height + self.adr.frame.size.height + self.contraindicationLabel.frame.size.height + self.contraindication.frame.size.height + self.noteLabel.frame.size.height + self.note.frame.size.height + self.interactionLabel.frame.size.height + self.interaction.frame.size.height + self.storageLabel.frame.size.height + self.storage.frame.size.height + self.shelflifeLabel.frame.size.height + self.shelflife.frame.size.height + self.codenameLabel.frame.size.height + self.codename.frame.size.height + self.standardLabel.frame.size.height + self.standard.frame.size.height + self.specificationdateLabel.frame.size.height + self.specificationdate.frame.size.height + self.refdrugcompanynameLabel.frame.size.height + self.refdrugcompanyname.frame.size.height path:path];
    
}

+ (CGFloat)heightWithText:(NSString *)text
{
    CGRect rect = [text boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - 20, 0) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil];
    
    return rect.size.height;
}

- (void)awakeFromNib {
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

   
}

@end
